// pages/message/message.js
const app = getApp()
const api = require("../../config/api.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeNames: ['1'],

    list:null,
    user:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.stopPullDownRefresh()
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      user:app.globalData.user
    })
    console.log(this.data.user)

    if(this.data.user==null){
     wx.showToast({
       title: '请先登录',
       icon:"none"
     })
    }else if(this.data.user.role==2){
      this.administratorFind()
    }

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onLoad()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },
  pass(e){
    var that=this
    console.log(e)
    var holiday=e.currentTarget.dataset.item
    wx.showModal({
      title: '提示',
      content: '您确定通过吗',
      success (res) {
        if (res.confirm) {
          holiday.approveName=that.data.user.username
          holiday.result=true
          holiday.state=true
          holiday.approveId=that.data.user.userId
          that.approve(holiday)
          console.log( e.currentTarget.dataset.item)
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  Nopass(){
    var that=this
    console.log(e)
    var holiday=e.currentTarget.dataset.item
    wx.showModal({
      title: '提示',
      content: '您确定不通过吗',
      success (res) {
        if (res.confirm) {
          holiday.approveName=that.data.user.username
          holiday.result=false
          holiday.state=true
          holiday.approveId=that.data.user.userId
          that.approve(holiday)
          console.log( e.currentTarget.dataset.item)
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  administratorFind(){

    var that=this
    wx.request({
      url: api.administratorFind,
      method:"GET",
      success(res){
      console.log(res)
      that.setData({
        list:res.data.data
      })
      console.log(that.data.list)
      }
    })
  },
  approve(e){
    var that=this
    console.log(e)
    wx.request({
      url: api.approve,
      method:"POST",
      data: JSON.stringify(e),
      success(e){
       wx.showToast({
         title: '操作成功',
       })
       that.administratorFind()
      }

    })

  }
})